
function basePath(){
    //获取当前网址，如： http://localhost:8080/ems/Pages/Basic/Person.jsp
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录，如： /ems/Pages/Basic/Person.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8080
    var localhostPath = curWwwPath.substring(0, pos);
    //获取带"/"的项目名，如：/ems
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    //获取项目的basePath   http://localhost:8080/ems/
    var basePath=localhostPath+projectName+"/";
    return basePath;
};

jQuery(document).ready(function() {
	initTable();

	//新增
	$('#addbtn').click(function(){
		setModalSize();
    	
    	$('#ifModal').attr("src", "add.html");
    	
		$('#modalTile').html("新增咨询投诉");
		$("#modalConsulting").modal('show');
	});
	//详细页关闭
	$("#modalConsulting").on("hidden.bs.modal", function() {
		$('#consultingTable').bootstrapTable(('refresh')); 
	});
	//保存数据事件
	$('#save').click(function(){

		$("#ifModal")[0].contentWindow.save();
		
	});
	
});	
//js函数
function initTable(){	
	
	$('#consultingTable').bootstrapTable({
		method: 'post',
	    url: basePath() + 'consulting/list.do',
	    pagination: true, //分页
	    dataType: "json",
        contentType: "application/json",
        pageList: [10, 20, 50, 100],  //可供选择的每页的行数（*）
        striped: true,      //是否显示行间隔色
        sidePagination: "server",
        ////查询参数,每次调用是会带上这个参数，可自定义                         
        queryParams:function(params) {
            return {
                	pageNum: params.offset / params.limit + 1,
                	pageSize: params.limit,
//                	publicStatus:"1"
                };
        },
	    columns: [{  
            field : 'number',  
            title : '序号',  
            align : 'center',
            width : '80px',
            formatter : function(value, row, index) { 
// 		                return index + 1;  
                var page = $('#consultingTable').bootstrapTable("getPage");  
                return page.pageSize * (page.pageNumber - 1) + index + 1;  
            }  
        }, {
	        field: 'complainTitle',
	        title: '标题',
	        align : 'center',
	        events: operateEvents,
            formatter: operateFormatter
	    },{
	        field: 'complainType',
	        title: '类型',
	        align : 'center',
	    },{
	        field: 'complainStatus',
	        title: '状态',
	        align : 'center',
	        formatter:function(value,row,index){
	        	var result = value;
	        	if(value == "1")
	        		result = "已处理";
	        	else 							
        			result = "未处理";
	        	return result;
	        }
	    },{
	        field: 'publicStatus',
	        title: '是否公开',
	        align : 'center',
	        formatter:function(value,row,index){
	        	var result = value;
	        	if(value == "1")
	        		result = "公开";
	        	else 							
        			result = "不公开";
	        	return result;
	        }
	    },{
	        field: 'leaveTime',
	        align : 'center',
	        title: '留言时间'
	    }]
	});
}
//标题
function operateFormatter(value, row, index) {
//	if(row.complainStatus == '0'){
//		return value;
//	}else{
//	}
	return ['<a class="detail" style="color:#000">'+row.complainTitle+'</a>'].join('');
    
}

window.operateEvents = {
	'click .detail': function (e, value, row, index) {
		$("#save").css("display","none");
    	var complainId = row.complainId;
    	
//    	setModalSize();
//    	
//    	$('#ifModal').attr("src", "detail.html?complainId=" + complainId);
//    	
//		$('#modalTile').html("咨询投诉");
//		$("#modalConsulting").modal('show');
    	
    	window.location.href = './detail.html?complainId='+complainId;
    	
    },
};





